//
//  CustomSettingsAlertView.m
//  DriftDog
//
//  Created by rimi on 15/9/10.
//  Copyright (c) 2015年 廖马林. All rights reserved.
//

#import "CustomSettingsAlertView.h"

@interface CustomSettingsAlertView ()

@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) Block block;

@end

@implementation CustomSettingsAlertView

+ (CustomSettingsAlertView *)showViewWithCustomAlertType:(CustomAlertType)type title:(NSString *)title complete:(Block)block{

    CustomSettingsAlertView *customSettingsAlertView = [[CustomSettingsAlertView alloc] initWithAlertType:type title:title complete:block];
    
    [customSettingsAlertView show];
    
    return customSettingsAlertView;
}

- (instancetype)initWithAlertType:(CustomAlertType)type title:(NSString *)title complete:(Block)block {

    self = [super init];
    if (self) {
        
        self.title = title;
        self.block = block;
        [self initializeUserInterfaces];
        if (type == LMLTextFieldType) {
            
            [self initializeTextFieldInterface];
        }else if (type == LMLTextViewType) {
        
            [self initializeTextViewInterface];
        }
    }
    return self;
}

#pragma mark - init

- (void)initializeUserInterfaces {

    /* title label */
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds), 44)];
    label.backgroundColor = [UIColor orangeColor];
    label.text = self.title;
    label.textColor = [UIColor whiteColor];
    label.textAlignment = NSTextAlignmentCenter;
    [self addSubview:label];
    
    /* 确定按钮 */
    UIButton *confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
    confirmButton.frame = CGRectMake(CGRectGetMidX(self.frame) + 30 * DHFlexibleVerticalMutiplier(), CGRectGetHeight(self.bounds) - 40, 50 * DHFlexibleVerticalMutiplier(), 37 * DHFlexibleVerticalMutiplier());
   
    confirmButton.backgroundColor = [UIColor orangeColor];
    [confirmButton setTitle:@"确定" forState:UIControlStateNormal];
    [confirmButton addTarget:self action:@selector(confirmation:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:confirmButton];
    
    /* 取消按钮 */
    UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
    cancelButton.frame = CGRectMake(CGRectGetMidX(self.frame) - 187* DHFlexibleVerticalMutiplier(), CGRectGetHeight(self.bounds) - 40, 50 * DHFlexibleVerticalMutiplier(), 37 * DHFlexibleVerticalMutiplier());
    
    cancelButton.backgroundColor = [UIColor orangeColor];
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [cancelButton addTarget:self action:@selector(cancel:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:cancelButton];
    
}

- (void)initializeTextFieldInterface {

    /* textField */
    UITextField *textField = [[UITextField alloc] initWithFrame:DHFlexibleFrame(CGRectMake(0, 0, 200, 50), NO)];
    textField.center = self.center;
    textField.layer.cornerRadius = 4;
    textField.layer.borderWidth = 2;
    textField.layer.borderColor = [UIColor colorWithWhite:0 alpha:0.3].CGColor;
    textField.placeholder = @"请输入要修改为的昵称";
    
    [self addSubview:textField];
}

- (void)initializeTextViewInterface {

    /* textView */
    UITextView *textView = [[UITextView alloc] initWithFrame:DHFlexibleFrame(CGRectMake(0, 0, 200, 150), NO)];
    textView.center = DHFlexibleCenter(self.center);
    textView.layer.cornerRadius = 4;
    textView.layer.borderWidth = 2;
    textView.layer.borderColor = [UIColor colorWithWhite:0 alpha:0.3].CGColor;
    //textView.placeholder = @"请输入要修改为的个性签名";
    
    [self addSubview:textView];
}

#pragma mark - responds event

- (void)confirmation:(UIButton *)sender {

    
}

- (void)cancel:(UIButton *)sender {

    
}

@end
